/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication6.DomainLayer;

/**
 *
 * @author meydlo
 */
import java.util.ArrayList;
public class WorkerRecords{

    private static WorkerRecords workerRecords;
    private ArrayList<Worker> workerList;

    //
    private WorkerRecords(){
        workerList = new ArrayList<Worker>();
    }

    //
    public static WorkerRecords getWorkerRecords(){
        if(workerRecords==null)
        {
            workerRecords=new WorkerRecords();
        }
        return workerRecords;
    }

    //
    public void addWorker(Worker worker)
    {
        workerList.add(worker);
    }

    //
    public Worker workerByID(long id)
    {
        for(int i=0; i<workerList.size();i++){
            if(workerList.get(i).getId()==id)
            {
                return workerList.get(i);
            }
        }
        System.out.println("Worker wasn't found");
        return null;
    }



    //
    public void deleteWorker(long id)
    {
        if(workerByID(id)!=null){
            workerList.remove(workerByID(id));
        }
    }



    //
    public ArrayList<Worker> getWorkerList()
    {
        return workerList;
    }



    public void printWorkerList()
    {
        for(Worker worker : workerList){
            System.out.println("id: "+worker.getId()+" | name: "+worker.getName());
        }
    }

    protected void setWorkersList(ArrayList arrayList)
    {
        workerList=arrayList;
    }

     //statistics purpose
    public int getNoOfWorkers()
    {
        int noOfWorkers=workerList.size();
        return noOfWorkers;
    }

}
